<?php
/**
 */
/**
 * zeus_quickform
 *
 * @package
 * @author xexplorer
 * @copyright Copyright (c) 2008
 * @version $Id$
 * @access public
 */
class zeus_quickform {
    private $aOptions;
    private $sElement;
    private $sWrap;
    /**
     * Constructor
     *
     * @access protected
     */
    public function __construct($options = array())
    {
        $this->aOptions = $options;
        $this->sWrap = "\n\t";
    }
    public function __destruct()
    {
    }
    /**
     * Zeus_DataGrid::__set()
     *
     * @param mixed $name
     * @param mixed $value
     * @return
     */
    public function __set($name, $value)
    {
        $this->$name = $value;
    }
    /**
     * Zeus_DataGrid::__get()
     *
     * @param mixed $name
     * @return
     */
    public function __get($name)
    {
        return $this->$name;
    }
    /**
     * zeus_quickform::start()
     *
     * @return
     */
    public function start()
    {
        $form_start = "<FORM";
        if (isset($this->aOptions) && is_array($this->aOptions)) {
            foreach($this->aOptions AS $key => $value) {
                $form_start .= " " . $key . "='" . $value . "'";
            }
            $form_start .= " />";
        } else {
            $form_start .= " />";
        }
        $form_start .= $this->sWrap;
        return $form_start;
    }
    /**
     * zeus_quickform::end()
     *
     * @return
     */
    public function end()
    {
        $form_end = "</FORM>";
        return $form_end;
    }
    /**
     * zeus_quickform::addElement()
     *
     * @param string $sType
     * @param string $mName
     * @param mixed $sPrompt
     * @param mixed $mOptions
     * @return
     */
    public function addElement($type = '', $options)
    {
        switch ($type) {
            case "text":
            case "password":
            case "file":
            case "image":
            case "hidden":
            case "button":
            case "submit":
            case "checkbox":
            case "radio":
                $this->sElement = "<INPUT type='" . $type . "'";
                $this->setOptions($options);
                break;
            case "textarea":
                $this->sElement = "<TEXTAREA type='" . $type . "'";
                $this->setOptions($options);
                break;
            default: $this->sElement = "<INPUT type='" . $type . "'";
                $this->setOptions($options);
                break;
        }
        $this->sElement .= $this->sWrap;
        return $this->sElement;
    }
    /**
     * zeus_quickform::addSelect()
     *
     * @param mixed $property
     * @param mixed $options
     * @return
     */
    public function addSelect($property, $options, $current = null)
    {
        $this->sElement = "<SELECT ";
        $this->setOptions($property);
        if (isset($options) && is_array($options)) {
            foreach($options AS $op_key => $op_value) {
                if ($op_key == $current) {
                    $selected = "selected";
                } else {
                    $selected = "";
                }
                $this->sElement .= "<OPTION " . $selected . " value='" . $op_key . "'>" . $op_value . "</OPTION>";
            }
            $this->sElement .= "</SELECT>";
        } else {
            $this->sElement .= "</SELECT>";
        }
        $this->sElement .= $this->sWrap;
        return $this->sElement;
    }
    /**
     * zeus_quickform::addLabel()
     *
     * @param string $label_key
     * @param mixed $label_value
     * @return
     */
    public function addLabel($label_key = '', $label_value)
    {
        $this->sElement = "<LABEL FOR='" . $label_key . "'>" . $label_value . "</LABEL>";
        return $this->sElement;
    }
    /**
     * zeus_quickform::setOptions()
     *
     * @param mixed $options
     * @return
     */
    private function setOptions($options)
    {
        if (isset($options) && is_array($options)) {
            foreach($options AS $key => $var) {
                $this->sElement .= " " . $key . "='" . $var . "'";
            }
            $this->sElement .= " />";
        } else {
            $this->sElement .= " />";
        }
    }
}

/**
 * show_form_row()
 *
 * @param mixed $formObj
 * @param array $element
 * @return
 */
function showFormRow($oForm, $aElement = array())
{
    $row[] = "<tr class='form-field'>";
    $row[] = "<th scope='row'>";
    $row[] = "<label for='" . $aElement['label']['for'] . "'>" . $aElement['label']['name'] . "</label></th>";
    $row[] = "<td>" . $oForm->addElement($aElement['form']['type'], $aElement['form']['options']) . "</td>";
    $row[] = "</tr>";
    return implode("\n\t", $row);
}

?>